<template>
  <view>
    <view v-if="isauth == 0 || isauth == 3">
      <view class="name">
        <view style="margin-right: 96rpx">姓名</view>
        <input type="text" placeholder="请输入姓名" style="flex: 1; font-size: 28rpx" v-model="name" />
      </view>
      <view class="name">
        <view style="margin-right: 30rpx">身份证号</view>
        <input type="text" placeholder="请输入身份证号" style="flex: 1; font-size: 28rpx" maxlength="18" v-model="idcard" />
      </view>
      <view class="btnsubmit" @click="submit">提交</view>
    </view>
    <view v-else>
      <view class="name">
        <view style="margin-right: 96rpx">姓名</view>
        <input type="text" placeholder="请输入姓名" style="flex: 1; font-size: 28rpx" :value="name" disabled />
      </view>
      <view class="name">
        <view style="margin-right: 30rpx">身份证号</view>
        <input type="text" placeholder="请输入身份证号" style="flex: 1; font-size: 28rpx" :value="idcard" disabled maxlength="18" />
      </view>
      <view class="alreadysubmit" v-if="isauth == 2" disabled>已认证</view>
      <view class="alreadysubmit" v-if="isauth == 1" disabled>申请中</view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      name: '',
      idcard: '',
      isauth: ''
    };
  },
  onLoad() {
    this.gteuserinfo();
  },
  methods: {
    // 获取个人信息
    async gteuserinfo() {
      const res = await uni.$http.post('user/index', {
        user_id: JSON.parse(uni.getStorageSync('userinfo')).user_id,
        token: JSON.parse(uni.getStorageSync('userinfo')).token
      });

      this.name = res.data.data.name;
      this.idcard = res.data.data.idcard;
      this.isauth = res.data.data.is_auth;
    },
    // 提交实名
    submit() {
      var regIdCard = /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;
      console.log(regIdCard.test(this.idcard));
      if (regIdCard.test(this.idcard)) {
        uni.$http.post('user/profile', {
          name: this.name,
          idcard: this.idcard,
          token: JSON.parse(uni.getStorageSync('userinfo')).token
        });
        this.gteuserinfo();
      } else {
        uni.showToast({
          title: '输入身份证号不正确',
          icon: 'none'
        });
      }
    }
  }
};
</script>

<style lang="less">
view {
  box-sizing: border-box;
}
.name {
  display: flex;
  align-items: center;
  width: 750rpx;
  height: 120rpx;
  line-height: 120rpx;
  padding-left: 40rpx;
  background: #ffffff;
  border-radius: 0rpx 0rpx 0rpx 0rpx;
}
.btnsubmit {
  width: 670rpx;
  height: 90rpx;
  text-align: center;
  line-height: 90rpx;
  color: #fff;
  margin-left: 40rpx;
  margin-top: 800rpx;
  background: linear-gradient(180deg, #0398ff 0%, #21e5ff 100%);
  border-radius: 100rpx 100rpx 100rpx 100rpx;
}
.alreadysubmit {
  width: 670rpx;
  height: 90rpx;
  background: #999999;
  color: #fff;
  text-align: center;
  line-height: 90rpx;
  margin-left: 40rpx;
  margin-top: 800rpx;
  border-radius: 100rpx 100rpx 100rpx 100rpx;
  opacity: 1;
}
</style>
